<?php $this->load->view('templates/backend/header'); ?>
<!--body-->

<style>
    .table .new,.notice{
        font-weight: bold;
        color:#D65824;
    }
    .auto-load{
        text-align: center;
        font-size: 20px;
        margin: 10px 0;
    }
</style>
<div style="text-align:center;font-size: 55px;margin: 47px 0;"><?php if(!empty($lists)){ echo $this->lang->line('debts_list');}?></div>

<div class="auto-load">
    <div id="icon-load"></div>
    <div id="notice"></div>
    <span id="loading"><span style="height:17px;font-size:15px;">&nbsp;</span></span>
</div>

<table class="table table-striped table-bordered dataTable" id="data-table" width="100%" aria-describedby="data-table_info" style="width: 100%;">
    <?php if(!empty($lists)){?>
    <thead>
        <tr role="row">
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('customerID');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('reason');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('maturity');?></th>           
            <th width="10%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="" style="width: 248px;"><?php echo $this->lang->line("status");?></th>
            <th width="10%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="" style="width: 248px;"><?php echo $this->lang->line("payment_confirm");?></th>
        </tr>
    </thead>
    <?php }?>
    <tbody role="alert" aria-live="polite" aria-relevant="all">
        <?php
        if(!empty($lists)){
            foreach($lists AS $key => $value){
                if($key%2 == 0){
                    $old = 'new';
                } else {
                    $old = 'old';
                }
                echo '<tr class="'.$old.'">';
                
                echo '<td class="">'.$value->customerID.'</td>';
                echo '<td class="">'.$value->reason.'</td>';
                echo '<td class="">'.date('d-m-Y',$value->debts).'</td>';
                if($value->payment_confirm == 1){
                    echo '<td class=""><img src="/static/templates/backend/images/icon/ok.png" />Đã duyệt</td>';
                } else {
                    echo '<td class=""><a style="cursor: pointer;" id="confirm">Xác nhận</a> <sapn id="simple-msg-'.$value->customerID.'"></span></td>';
                }
                if($value->payment_collect == 1){
                    echo '<td class=""><img src="/static/templates/backend/images/icon/ok.png" />Đã thu tiền</td>';
                } else {
                    echo '<td class=""><a style="cursor: pointer;" id="confirm">Xác nhận</a> <sapn id="simple-msg-'.$value->customerID.'"></span></td>';
                }
                
                echo '</tr>';
            }
        } else {
            echo 'Không tìm thấy thông tin';
        }
        ?>
    </tbody>
</table>
<!--body-->

<div id="simple-msg-test-code"></div>
<?php $this->load->view('templates/backend/footer'); ?>

<script>

$(document).ready(function() {
    $("#confirm").live('click',function() {
        $("#simple-msg-<?php echo $value->customerID;?>").html('<img src="http://hayageek.com/examples/jquery/ajax-form-submit/loading.gif" />');
        $.ajax(
        {
            url : '/auth/debts/confirm?id=<?php echo $value->customerID;?>',
            success:function(data)
            {
                if(data == 1){
                    $("#simple-msg-<?php echo $value->customerID;?>").html('<img src="/static/templates/backend/images/icon/ok.png" /> Duyệt thành công!');
                } else {
                    $("#simple-msg-<?php echo $value->customerID;?>").html('<img src="/static/templates/backend/images/icon/error.png" /> Duyệt thất bại!');
                }
            },
            error: function() 
            {
                $("#simple-msg").html('Vui lòng liên hệ Admin!');
            }
        });
    });
});

//auto refesh

(function($)
{
    $(document).ready(function()
    {
        $.ajaxSetup(
        {
            cache: false,
            beforeSend: function() {
                $('#notice').hide();
                $('#loading').show();
            },
            complete: function() {
                //$('#loading').hide();
                $('#notice').show();
            },
            success: function() {
                //$('#loading').hide();
                $('#notice').show();
            }
        });
        var $container = $("#notice");
        $container.load("/auth/debts/ajaxAutoload");
//        icon-load
$("#icon-load").html("<img src='/static/templates/backend/images/icon/loading.gif' />");
        var refreshId = setInterval(function()
        {
            $container.load('/auth/debts/ajaxAutoload');
        }, 5000);//2h refesh 36 000 000 000
    });
})(jQuery);
</script>